# - 实现斐波那契函数(for循环, while循环)
# - 如果遇到可以转换为`int`类型的参数, 则转换, 否则抛出自定义异常`ParamsTypeError`

def fibonacci_for(x):
    a, b = 0, 1
    list_1 = []
    for i in range(x):
        i = a
        a += b
        b = i
        list_1.append(i)
    print(list_1)
    return None


def fibonacci_while(x):
    a, b, i, counter = 0, 1, 0, 0
    list_1 = []
    while counter < x:
        counter += 1
        i = a
        a += b
        b = i
        list_1.append(i)
    print(list_1)
    return None


def fibonacci_while_2(x):
    a, b, i, counter = 0, 1, 0, 0
    list_1 = []
    while True:
        counter += 1
        i = a
        a += b
        b = i
        list_1.append(i)
        if counter >= x:
            break
    print(list_1)
    return None


class ParamsTypeError(Exception):
    pass


if __name__ == '__main__':
    y = input("请输入斐波那契数字个数：\n")
    try:
        fibonacci_while(int(y))
    except Exception:
        raise ParamsTypeError("请输入正确的数字！")